package com.wlb.address.split.process;

import com.wlb.address.split.domain.AddrLevel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 词条融合的结果集合
 * User: xiaotong.dxt
 * Date: 13-8-8
 * Time: 下午12:08
 * To change this template use File | Settings | File Templates.
 */
public class FusionResultSet {
    private List<FusionResult> fusionResults = new ArrayList<FusionResult>();

    public AddrLevel lastLevel;

    public int size() {
        return fusionResults.size();
    }

    public boolean hasLevel(AddrLevel addrLevel) {
        if (addrLevelExist.containsKey(addrLevel) && addrLevelExist.get(addrLevel).intValue() == 1) {
            return true;
        }
        return false;
    }

    /**
     * 用于判断某一级别是否已经匹配到
     */
    private Map<AddrLevel, Integer> addrLevelExist = new HashMap<AddrLevel, Integer>();

    /**
     * 添加一个融合的词条元素
     *
     * @param strWordName
     * @param nLevel
     * @param nProp
     */
    public void insertWordtoResultSet(String strWordName, AddrLevel nLevel, int nProp) {
        FusionResult fsResult = new FusionResult();
        fsResult.strWordName = strWordName;
        fsResult.nLevel = nLevel;
        fsResult.nProp = nProp;
        fusionResults.add(fsResult);
        addrLevelExist.put(nLevel, 1);
    }

    public FusionResult peekLast() {
        if (fusionResults.size() > 0) {
            return fusionResults.get(fusionResults.size() - 1);
        }
        return null;
    }

    public FusionResult get(int index) {
        if (index >= fusionResults.size() || index < 0) {
            return null;
        } else {
            return fusionResults.get(index);
        }
    }

    public FusionResult popLast() {
        if (fusionResults.size() == 0)
            return null;
        else
            return fusionResults.remove(fusionResults.size() - 1);
    }


}
